/**********************************************
** @Author: phy
** @Date:   2017-12-12 14:17:37
** @Last Modified by:   phy
***********************************************/
package controllers

import (
	"fmt"
	"strconv"
	"strings"
	//"time"

	//"github.com/astaxie/beego"
	//"reflect"
	"WebAdminSys/libs"
	"WebAdminSys/models"
)

type UsersFinduserController struct {
	BaseController
}
func (self *UsersFinduserController) FindUserPage(){
	self.Data["pageTitle"] = "搜索用户"
	//self.Ctx.WriteString("MangeAdminController.List")
	self.display()
}
func (self *UsersFinduserController) UserList() {
	self.Data["pageTitle"] = "用户列表"
	//self.Ctx.WriteString("MangeAdminController.List")
	self.display()
}
func (self *UsersFinduserController) UserInfoTable() {
	//列表
	page, err := self.GetInt("page")
	if err != nil {
		page = 1
	}
	limit, err := self.GetInt("limit")
	if err != nil {
		limit = 30
	}

	self.pageSize = limit
	//查询条件
	//用户信息
	usercondition := self.GetString("userinfolist");
    userconditioninfo := self.GetString("userconditioninfo");
    //注册时间
    regfrontdatetime := self.GetString("regfrontdatetime");
    regbehinddatetime := self.GetString("regbehinddatetime");
    //登录时间
    loginfrontdatetime := self.GetString("loginfrontdatetime");
    loginbehinddatetime := self.GetString("loginbehinddatetime");
    //资产
    userchichanlt := self.GetString("userchichanlt");
    userchichangt := self.GetString("userchichangt");
    //玩家礼券
    userliquanlt := self.GetString("userliquanlt");
    userliquangt := self.GetString("userliquangt");
    //充值金额
    userczjelt := self.GetString("userczjelt");
    userczjegt := self.GetString("userczjegt");
    //礼物差(接收-赠送)：
    userlwclt := self.GetString("userlwclt");
    userlwcgt := self.GetString("userlwcgt");
    //背包钻石
    userbbzslt := self.GetString("userbbzslt");
    userbbzsgt := self.GetString("userbbzsgt");
    //总输赢：
    userzsylt := self.GetString("userzsylt");
    userzsygt := self.GetString("userzsygt");
    //当日输赢：
    userdrsylt := self.GetString("userdrsylt");
    userdrsygt := self.GetString("userdrsygt");
    //密保手机：
    usermbsj := self.GetString("usermbsj");
    //登录机器码：
    userdljqm := self.GetString("userdljqm");
    //最后登录IP：
    userzhdlip := self.GetString("userzhdlip");
    //注册IP：
    userzcip := self.GetString("userzcip");
    //帐号状态：
    userzhzt := self.GetString("userzhzt");
    //设备类型：
    usersblx := self.GetString("usersblx");
    //用户类型：
    useryhlx := self.GetString("useryhlx");
    //游戏平台：
    useryxpt := self.GetString("useryxpt");

     strsql := "";
     //推广号
   	if usercondition == "0" && userconditioninfo != "" {
		strsql = fmt.Sprintf("%s AND UI.GameID = %s",strsql,userconditioninfo);
	}
	//登录名
	if usercondition == "1" && userconditioninfo != "" {
		
		strsql = fmt.Sprintf("%s AND UI.ACCOUNT = '%s'",strsql,userconditioninfo);
	}
	//昵称
	if usercondition == "2" && userconditioninfo != "" {
		
		strsql = fmt.Sprintf("%s AND UI.NICKNAME = '%s'",strsql,userconditioninfo);
	}
	//UserID
	if usercondition == "3" && userconditioninfo != "" {
		strsql = fmt.Sprintf("%s AND UI.USERID = %s",strsql,userconditioninfo);	
	} 
	
	if regfrontdatetime != ""{
		strsql = fmt.Sprintf("%s AND UI.REGISTERTIME >= %s",strsql,libs.GetStringTimeToUnix(regfrontdatetime,"Y-m-d H:i:s"));	
	}
	if regbehinddatetime != ""{
		strsql = fmt.Sprintf("%s AND UI.REGISTERTIME <= %s",strsql,libs.GetStringTimeToUnix(regbehinddatetime,"Y-m-d H:i:s"));	
	}

	if loginfrontdatetime != ""{
		strsql = fmt.Sprintf("%s AND UI.LASTLOGINTIME >= %s",strsql,libs.GetStringTimeToUnix(loginfrontdatetime,"Y-m-d H:i:s"));	
	}
	if loginbehinddatetime != ""{
		strsql = fmt.Sprintf("%s AND UI.LASTLOGINTIME <= %s",strsql,libs.GetStringTimeToUnix(loginbehinddatetime,"Y-m-d H:i:s"));	
	}

	if userchichanlt != ""{
		strsql = fmt.Sprintf("%s AND UI.GOLD + UI.INSUREGOLD >= %s",strsql,userchichanlt);	
	}
	if userchichangt != ""{
		strsql = fmt.Sprintf("%s AND UI.GOLD + UI.INSUREGOLD <= %s",strsql,userchichangt);	
	}
	
	if userliquanlt != ""{
		strsql = fmt.Sprintf("%s AND UI.TICKET >= %s",strsql,userliquanlt);	
	}
	if userliquangt != ""{
		strsql = fmt.Sprintf("%s AND UI.TICKET <= %s",strsql,userliquangt);	
	}
	
	if userczjelt != ""{
		strsql = fmt.Sprintf("%s AND userczje >= '%s'",strsql,userczjelt);	
	}
	if userczjegt != ""{
		strsql = fmt.Sprintf("%s AND userczje <= '%s'",strsql,userczjegt);	
	}
	
	if userlwclt != ""{
		strsql = fmt.Sprintf("%s AND (UI.ALLBUYSCORE-UI.ALLSELLSCORE) >= %s",strsql,userlwclt);	
	}
	if userlwcgt != ""{
		strsql = fmt.Sprintf("%s AND UI.ALLBUYSCORE-UI.ALLSELLSCORE <= %s",strsql,userlwcgt);	
	}

	if userbbzslt != ""{
		strsql = fmt.Sprintf("%s AND UI.DIAMOND >= %s",strsql,userbbzslt);	
	}
	if userbbzsgt != ""{
		strsql = fmt.Sprintf("%s AND UI.DIAMOND <= %s",strsql,userbbzsgt);	
	}

	if userzsylt != ""{
		strsql = fmt.Sprintf("%s AND UI.ALLWINLOSE >= %s",strsql,userzsylt);	
	}
	if userzsygt != ""{
		strsql = fmt.Sprintf("%s AND UI.ALLWINLOSE <= %s",strsql,userzsygt);	
	}


	if userdrsylt != ""{
		strsql = fmt.Sprintf("%s AND UI.TODAYWINLOSE >= %s",strsql,userdrsylt);	
	}
	if userdrsygt != ""{
		strsql = fmt.Sprintf("%s AND UI.TODAYWINLOSE <= %s",strsql,userdrsygt);	
	}

	if usermbsj != ""{
		strsql = fmt.Sprintf("%s AND UI.MOBILE = '%s'",strsql,usermbsj);	
	}

	if userdljqm != ""{
		strsql = fmt.Sprintf("%s AND UI.MACHINE = '%s'",strsql,userdljqm);	
	}

	if userzhdlip != ""{
		strsql = fmt.Sprintf("%s AND UI.LASTLOGINIP = '%s'",strsql,userzhdlip);	
	}

	if userzcip != ""{
		strsql = fmt.Sprintf("%s AND UI.REGIESTIP = '%s'",strsql,userzcip);	
	}

	if userzhzt == "1" || userzhzt == "2" {
		tmp,_ := strconv.Atoi(userzhzt)
		strsql = fmt.Sprintf("%s AND UI.STATUS = %d",strsql,tmp -1);	
	}
	
	if usersblx == "1" || usersblx == "2" || usersblx == "3" {
		//tmp,_ := strconv.Atoi(usersblx)
		strsql = fmt.Sprintf("%s AND UI.DEVICE = %s",strsql,usersblx);	
	}

	if useryhlx == "1" || useryhlx == "2" || useryhlx == "3" || useryhlx == "4" || useryhlx == "5"{
		tmp,_ := strconv.Atoi(useryhlx)
		strsql = fmt.Sprintf("%s AND UI.LVSIGN = %d",strsql,tmp-1);	
	}

	if useryxpt == "1" || useryxpt =="2" || useryxpt =="3" {
		//tmp,_ := strconv.Atoi(usersblx)
		strsql = fmt.Sprintf("%s AND UI.PLATFORM = %s",strsql,useryxpt);	
	}

	result, count,_ := models.UserInfoListData(page, self.pageSize,strsql)
	list := make([]map[string]interface{}, len(result))
	for k, v := range result {
		row := make(map[string]interface{})
		row["UserID"] = v["A"]
		row["UserNickName"] = v["B"]

		row["regdatetime"] = v["C"];

		row["cichan"] = v["zichan"]
		row["liquan"] = v["E"]
		row["chongzhi"] = v["USERALLC"]
		row["zhuanshi"] = v["F"]
		row["zongsuy"] = v["G"]
		row["drsuy"] = v["H"]
		row["jslw"] = v["I"]
		strtmp := models.GetUserPlatformName(v["J"])+"," + models.GetUserDeviceName(v["K"])+","+models.GetUserLvSignName(v["L"]);
		row["yhlx"] = strtmp;
		row["yhsb"] =  v["K"]
		str,_ := models.GetUserLockStats(v["M"]);
		strtmp = models.GetUserStatusInFo(v["ROOMID"]) + ":"+ str
		row["yhzt"] = strtmp;
		row["zbwcsj"] =  v["N"]

		list[k] = row
	}

	TitleData,_,_ := models.UserInfoTitleData(strsql);

	self.ajaxTilteList("成功", MSG_OK, count,TitleData,list)	
	
}

func (self *UsersFinduserController) UserInfoPage() {
	self.Data["GameUserID"] = self.GetString("UserID");
	self.Data["GameUserNickName"] = self.GetString("UserNickName");
	
	strsql := fmt.Sprintf(" AND UI.GameID = %s",self.Data["GameUserID"]);
	ret,_ := models.UserInfoDataByCondtion(strsql);
	list := make(map[string]interface{})
	if len(ret) >= 1{
		list["GID"] = ret[0]["GAMEID"]
		list["UID"] = ret[0]["USERID"]
		list["UNAME"] = ret[0]["NICKNAME"]
		list["UACC"] = ret[0]["ACCOUNT"]
		list["REGT"] = ret[0]["REGISTERTIME"]
		list["REGIP"] = ret[0]["REGIESTIP"]
		list["LLT"] = ret[0]["LASTLOGINTIME"]
		list["LLIP"] = ret[0]["LASTLOGINIP"]
		list["MB"] = ret[0]["MOBILE"]
	
		list["GD"] = models.GetUserSex(ret[0]["GENDER"])
		
		list["JBI"] = ret[0]["GOLD"]
		list["IJBI"] = ret[0]["INSUREGOLD"]
		list["ZC"] = ret[0]["zichan"]
		list["CZ"] = ret[0]["USERALLC"]
		list["AWL"] = ret[0]["ALLWINLOSE"]
		list["ABS"] = ret[0]["ALLBUYSCORE"]
		list["ASS"] = ret[0]["ALLSELLSCORE"]
		list["TAWL"] = ret[0]["TODAYWINLOSE"]
		list["TAG"] = 0
		list["TC"] = ret[0]["TICKET"]
		list["DM"] = ret[0]["DIAMOND"]

		list["LVSN"] =  models.GetUserLvSignName(ret[0]["LVSIGN"])

		list["ACCST"],list["lockorUnLock"] = models.GetUserLockStats(ret[0]["STATUS"]);
		list["USLV"] = ret[0]["USERLEVEL"]
		list["USLVV"] = ret[0]["EXP"]
		list["VIPLV"] = ret[0]["VIPLEVEL"]
		list["VIPLVV"] = ret[0]["VIPEXP"]
		list["DES"] = ret[0]["DESCRIPTION"]
		list["MAC"] = ret[0]["MACHINE"]
	
		list["PFN"] = models.GetUserPlatformName(ret[0]["PLATFORM"])
	
		list["DEVN"] = models.GetUserDeviceName(ret[0]["DEVICE"])
		
		list["CHETASTR"],list["luckorUnluck"],list["CHEATT"] = models.GetUserContrlInFo(ret[0]["CHEATRATE"],ret[0]["CHEATSCORE"],ret[0]["CHEATLEFTSCORE"],ret[0]["CHEATENDTIME"],ret[0]["Is_follow"])
		list["UCHEATRATE"] = ret[0]["CHEATRATE"];
		list["UCHEATSCORE"] = ret[0]["CHEATSCORE"];
		list["UCHEATLEFTSCORE"] = ret[0]["CHEATLEFTSCORE"];
		list["UGH"] = ret[0]["Is_follow"]; 
		list["RID"] = models.GetUserStatusInFo(ret[0]["ROOMID"]);
		
		list["UW"] = 0
		list["WP"] = 0
		list["UL"] = 0
		list["UF"] = 0


	}
  		
	self.Data["GameUserInfo"] = list;
	self.display()
}
/*' 1000-修改金币 
	1001-修改作弊率 
	1002-账号状态 
	1003-修改用户类型(银商,普通用户)
	1004-礼物找回 
	1005-删除邮件 
	1006-修改钻石 
	1007-修改奖券
	1008-修改贵宾的推广号 
	1009-修改密码 
	1010-修改昵称和修改个性签名 
	1011-解绑手机 
	1012-关联点控 
	1013-给用户发邮件
	1014-关联锁定',
	1015-设置取消关怀
	 */
func (self *UsersFinduserController) UserContrlInfo() {
	CtrlType,err := self.GetInt("uCtrlType");
	if err != nil{
		self.ajaxMsg(err.Error(), MSG_ERR);
		return;
	}
	CtrlUserID,err := self.GetInt("uCtrlUserID");
	if err != nil{
		self.ajaxMsg(err.Error(), MSG_ERR);
		return;
	}
	CtrlUserIDI64,err := self.GetInt64("uCtrlUserID");
	if err != nil{
		self.ajaxMsg(err.Error(), MSG_ERR);
		return;
	}
	uCtrlReaSonStr := self.GetString("uCtrlReaSonStr");
	strOKMessage := "";
	if CtrlType == 1000{

		uCtrlAddGold,err := self.GetInt64("uCtrlAddGold");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		if uCtrlAddGold == 0 {
			self.ajaxMsg("添加金币为0", MSG_ERR);
		}
		uCtrlGold,err := self.GetInt64("uCtrlGold");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		tmp := (uCtrlGold *-1);
		if uCtrlAddGold < tmp {
				uCtrlAddGold = tmp;
		}

		uCtrlName := self.GetString("uCtrlName");
	
		ras := models.UserCtrlInfo{
			USERID:CtrlUserID,
			NTYPE:0,
			GOLD:uCtrlAddGold,
		}
		err = ras.UserCtrlInfoInsertValue();
		if err == nil{
			

			strOKMessage = fmt.Sprintf("给用户【%s(%d)】添加【%d】金币成功添加前金币【%d】！",uCtrlName,CtrlUserID,uCtrlAddGold,uCtrlGold);
			list := make(map[string]interface{})
			list["strOKMessage"] = strOKMessage;
			useGold := uCtrlGold + uCtrlAddGold;
			list["GoldS"] = useGold;
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			
			GmaddDataLog := models.GMAddRecord{

				Manager_id:self.userId,
				Manager_name:self.userName,
				User_id:CtrlUserIDI64,
				Nickname:uCtrlName,
				Gold_type:1,
				Amount:uCtrlAddGold,
				Operation_time:libs.GetDateNowString(),
				Explain:uCtrlReaSonStr,
				Unix_time:libs.GetCurSysTmeTimeToUnix(),
			}
			GmaddDataLog.GMAddRecordInSertValues();
			self.ajaxMsg(list, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);

	}else if CtrlType == 1001{


		uCtrlCheatRate,err := self.GetInt64("uCtrlCheatRate");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		if uCtrlCheatRate < -1000 || uCtrlCheatRate > 1000 {
			self.ajaxMsg("作弊率必须是-1000，1000之间", MSG_ERR);
		}
		uCtrlCheatScore,err := self.GetInt64("uCtrlCheatScore");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		if uCtrlCheatScore < 0 {
			self.ajaxMsg("作弊分数不能小于0", MSG_ERR);
		}

		uCtrlName := self.GetString("uCtrlName");
	
		UseroldInfo := models.ExtremVipUserInfoByUserID(CtrlUserIDI64,"USERID","GAMEID","NICKNAME","ALLWINLOSE","CHEATRATE","CHEATSCORE");

		//fmt.Println("wwwwwwwwwwwwwwwww",UseroldInfo)
		ras := models.UserCtrlInfo{
			USERID:CtrlUserID,
			NTYPE:1,
			CHEATRATE:uCtrlCheatRate,
			CHEATSCORE:uCtrlCheatScore,
			CHEATREASON:uCtrlReaSonStr,
		}
		err = ras.UserCtrlInfoInsertValue();
		if err == nil{
			strOKMessage = fmt.Sprintf("将用户【%s(%d)】的作弊率修改为【%d】作弊分数修改为【%d】成功！",uCtrlName,CtrlUserID,uCtrlCheatRate,uCtrlCheatScore);
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			list := make(map[string]interface{})
			list["strOKMessage"] = strOKMessage;
			list["uCtrlCheatRate"] = uCtrlCheatRate;
			list["uCtrlCheatScore"] = uCtrlCheatScore;
			
			userCheatelog := models.GMChangeCheatRecord{
				GMID:self.userId,
				GMNAME:self.userName,
				NewlCheatLimit:uCtrlCheatScore,
				NewlCheatRate:uCtrlCheatRate,
				Reson:uCtrlReaSonStr,
			}

			userCheatelog.GMChangeCheatRecordInsertValue(UseroldInfo);

			self.ajaxMsg(list, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);

	}else if CtrlType == 1002{
		uCtrlStatus,err := self.GetInt64("uCtrlStatus");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}

		iCtrlStatus,err := self.GetInt("uCtrlStatus");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		uCtrlName := self.GetString("uCtrlName");
		if uCtrlStatus != 0 && uCtrlStatus != 1 {
			self.ajaxMsg("状态值不正确！", MSG_ERR);
			return;
		}
		if iCtrlStatus != 0 && iCtrlStatus != 1 {
			self.ajaxMsg("状态值不正确！", MSG_ERR);
			return;
		}
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		ras := models.UserCtrlInfo{
			USERID:CtrlUserID,
			NTYPE:2,
			STATUS:uCtrlStatus,
			CHEATREASON:uCtrlReaSonStr,
		}
		err = ras.UserCtrlInfoInsertValue();
		if err == nil{
			str := ""
			if uCtrlStatus  == 1{
				str = 	"锁定用户"
			}else if uCtrlStatus == 0{
				str = 	"解锁用户"
			}
			
			strOKMessage = fmt.Sprintf("%s【%s(%d)】成功！",str,uCtrlName,CtrlUserID);
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			GMLockUSer := models.GMForbidUserRecord{
				USERID:CtrlUserIDI64,
				GAMEID:CtrlUserIDI64,
				TYPE:iCtrlStatus, 
				CONTEXT:uCtrlReaSonStr,
				GMNAME:self.userName,
				GMID:self.userId,
			}
			GMLockUSer.GMForbidUserRecordInsertValue()
			self.ajaxMsg(strOKMessage, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);
		
	}else if CtrlType == 1003{
		
		uCtrlNewUserKind,err := self.GetInt64("uCtrlNewUserKind");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		uCtrlNewUserKindint,err := self.GetInt("uCtrlNewUserKind");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}

		uCtrlNewUserKind = uCtrlNewUserKind -1;
		uCtrlNewUserKindint = uCtrlNewUserKindint -1;
		if  uCtrlNewUserKind < 0 || uCtrlNewUserKind >5 {
			self.ajaxMsg("推广号有误", MSG_ERR);
		}
		uCtrlName := self.GetString("uCtrlName");
		
		dataSup := models.SuperVipInfo{
			UserID:CtrlUserIDI64,
			LVSIGN:uCtrlNewUserKindint,
		}
		err = dataSup.ModefySuperVipInfo();
		if err != nil{
			self.ajaxMsg(err.Error(), MSG_ERR);
			return ;
		}

		ras := models.UserCtrlInfo{
			USERID:CtrlUserID,
			NTYPE:3,
			LVSIGN:uCtrlNewUserKind,
			CHEATREASON:uCtrlReaSonStr,
		}
		str := models.GetUserLvSignName(strconv.FormatInt(uCtrlNewUserKind,10));  
		err = ras.UserCtrlInfoInsertValue();
		if err == nil{
			strOKMessage = fmt.Sprintf("将用户【%s(%d)】的类型修改为【%d-%s】成功！",uCtrlName,CtrlUserID,uCtrlNewUserKind,str);
			list := make(map[string]interface{})
			list["strOKMessage"] = strOKMessage;
			
			list["userkind"] = str;
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			self.ajaxMsg(list, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);
		
	}else if CtrlType == 1004{
		
	}else if CtrlType == 1005{
		
	}else if CtrlType == 1006{
		uCtrlAddGold,err := self.GetInt64("uCtrlAddGold");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		if uCtrlAddGold == 0 {
			self.ajaxMsg("添加钻石为0", MSG_ERR);
		}
		uCtrlGold,err := self.GetInt64("uCtrlGold");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		tmp := (uCtrlGold *-1);
		if uCtrlAddGold < tmp {
				uCtrlAddGold = tmp;
		}

		uCtrlName := self.GetString("uCtrlName");
	
		ras := models.UserCtrlInfo{
			USERID:CtrlUserID,
			NTYPE:6,
			DIAMOND:uCtrlAddGold,
		}
		err = ras.UserCtrlInfoInsertValue();
		if err == nil{
			

			strOKMessage = fmt.Sprintf("给用户【%s(%d)】添加【%d】钻石成功添加钻石币【%d】！",uCtrlName,CtrlUserID,uCtrlAddGold,uCtrlGold);
			list := make(map[string]interface{})
			list["strOKMessage"] = strOKMessage;
			useGold := uCtrlGold + uCtrlAddGold;
			list["GoldS"] = useGold;
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
				GmaddDataLog := models.GMAddRecord{

				Manager_id:self.userId,
				Manager_name:self.userName,
				User_id:CtrlUserIDI64,
				Nickname:uCtrlName,
				Gold_type:2,
				Amount:uCtrlAddGold,
				Operation_time:libs.GetDateNowString(),
				Explain:uCtrlReaSonStr,
				Unix_time:libs.GetCurSysTmeTimeToUnix(),
			}
			GmaddDataLog.GMAddRecordInSertValues();
			self.ajaxMsg(list, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);
		
	}else if CtrlType == 1007{
		uCtrlAddGold,err := self.GetInt64("uCtrlAddGold");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		if uCtrlAddGold == 0 {
			self.ajaxMsg("添加礼券为0", MSG_ERR);
		}
		uCtrlGold,err := self.GetInt64("uCtrlGold");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		tmp := (uCtrlGold *-1);
		if uCtrlAddGold < tmp {
				uCtrlAddGold = tmp;
		}

		uCtrlName := self.GetString("uCtrlName");
	
		ras := models.UserCtrlInfo{
			USERID:CtrlUserID,
			NTYPE:7,
			TICKET:uCtrlAddGold,
		}
		err = ras.UserCtrlInfoInsertValue();
		if err == nil{
			

			strOKMessage = fmt.Sprintf("给用户【%s(%d)】添加【%d】礼券成功添加礼券币【%d】！",uCtrlName,CtrlUserID,uCtrlAddGold,uCtrlGold);
			list := make(map[string]interface{})
			list["strOKMessage"] = strOKMessage;
			useGold := uCtrlGold + uCtrlAddGold;
			list["GoldS"] = useGold;
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			GmaddDataLog := models.GMAddRecord{
				Manager_id:self.userId,
				Manager_name:self.userName,
				User_id:CtrlUserIDI64,
				Nickname:uCtrlName,
				Gold_type:3,
				Amount:uCtrlAddGold,
				Operation_time:libs.GetDateNowString(),
				Explain:uCtrlReaSonStr,
				Unix_time:libs.GetCurSysTmeTimeToUnix(),
			}
			GmaddDataLog.GMAddRecordInSertValues();
			self.ajaxMsg(list, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);
		
	}else if CtrlType == 1008{
		uCtrlNewGameID,err := self.GetInt64("uCtrlNewGameID");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		uCtrlNewGameIDint,err := self.GetInt("uCtrlNewGameID");
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		if  uCtrlNewGameID <= 0 {
			self.ajaxMsg("推广号有误", MSG_ERR);
		}

		uCtrlName := self.GetString("uCtrlName");
	
		userDatTmp := models.UserInfo{
			USERID:CtrlUserID,
		}
		err = userDatTmp.ModefyUserInfoUserID(CtrlUserID,uCtrlNewGameIDint);
		if err != nil{
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		err,nLvSigin := models.GetUserUserInfoSigin(uCtrlNewGameIDint);
		if err != nil{
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		uservipData := models.SuperVipInfo{
			UserID:CtrlUserIDI64,
			LVSIGN:nLvSigin,
		}
		err = uservipData.ModefySuperVipUserID(uCtrlNewGameID);
		if err != nil{
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		ras := models.UserCtrlInfo{
			USERID:CtrlUserID,
			NTYPE:8,
			DESGAMEID:uCtrlNewGameID,
			CHEATREASON:uCtrlReaSonStr,
		}
		err = ras.UserCtrlInfoInsertValue();
		if err == nil{
			strOKMessage = fmt.Sprintf("将用户【%s(%d)】的推广号由【%d】改为【%d】成功！",uCtrlName,CtrlUserID,CtrlUserID,uCtrlNewGameIDint);
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			list := make(map[string]interface{})
			list["strOKMessage"] = strOKMessage;
			list["newuseID"] = uCtrlNewGameIDint;
			self.ajaxMsg(list, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);
	}else if CtrlType == 1009{
		uCtrlInfo := self.GetString("upass1");
		uCtrlInfo2 := self.GetString("upass2");
		uCtrNickName := self.GetString("uCtrNickName");
		if uCtrlInfo != uCtrlInfo2{
			self.ajaxMsg("两次密码不一致！", MSG_ERR);
		}
		if strings.Count(uCtrlInfo,"")-1 < 6 {
			self.ajaxMsg("密码少于6位！", MSG_ERR);
		}
		md5pass := libs.GetEnCodeByMd5(uCtrlInfo); 
		ras := models.UserCtrlInfo{
			USERID:CtrlUserID,
			NTYPE:9,
			CHANGEPASSWD:md5pass,
			CHEATREASON:uCtrlReaSonStr,
		}
		err = ras.UserCtrlInfoInsertValue();
		if err == nil{
			strOKMessage = fmt.Sprintf("将用户【%s(%d)】密码成功！",uCtrNickName,CtrlUserID);
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			self.ajaxMsg(strOKMessage, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);
		return
		
	}else if CtrlType == 1010{
		uCtrNickName := self.GetString("uCtrNickName");
		uNewCtrlNickName := self.GetString("uNewCtrlNickName");
		olduDes := self.GetString("uOldDes");
		newuDes := self.GetString("uNewDes");
		str := ""
		strUserEndNickNick := uCtrNickName; 
		if uCtrNickName != uNewCtrlNickName && uNewCtrlNickName != ""{
			ras := models.UserCtrlInfo{
				USERID:CtrlUserID,
				NTYPE:10,
				CHANGENICKNAME:uNewCtrlNickName,
				CHEATREASON:uCtrlReaSonStr,
			}
			err = ras.UserCtrlInfoInsertValue();

			if err == nil{
				str += "修改用户昵称成功"
				strUserEndNickNick = uNewCtrlNickName; 
			}else{
				str += "修改用户昵称失败"
			}
		}
		
		if 	olduDes !=newuDes {	
			ras := models.UserCtrlInfo{
				USERID:CtrlUserID,
				NTYPE:13,
				SZSIGN:newuDes,
				CHEATREASON:uCtrlReaSonStr,
			}
			err = ras.UserCtrlInfoInsertValue();

			if err == nil {
				if str == ""{
					str += "修改用户签名成功！"	
				}else{
					str += "-修改用户签名成功！"	
				}
				
			}else{
				if str == ""{
					str += "修改用户签名失败！"	
				}else{
					str += "-修改用户签名失败！"	
				}
			}
		}
		strOKMessage = fmt.Sprintf("修改用户：【%s(%d)】的信息【%s】",uCtrNickName,CtrlUserID,str);
	
		self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
		list := make(map[string]interface{})
		list["strOKMessage"] = strOKMessage;
		list["usernewnickName"] = strUserEndNickNick;
		self.ajaxMsg(list, MSG_OK);
		return;
		
	}else if CtrlType == 1011{

		uCtrNickName := self.GetString("uCtrlName");
		ras := models.UserCtrlInfo{
			USERID:CtrlUserID,
			NTYPE:11,
			CHEATREASON:uCtrlReaSonStr,
		}
		err = ras.UserCtrlInfoInsertValue();
		if err == nil{
			strOKMessage = fmt.Sprintf("将用户【%s(%d)】手机解绑成功！",uCtrNickName,CtrlUserID);
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			self.ajaxMsg(strOKMessage, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);
		
	}else if CtrlType == 1012{
		
	}else if CtrlType == 1013{

		uUserID,err := self.GetInt("uUserID");
		if err != nil{
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		uMailTitle := self.GetString("uMailTitle");
		if uMailTitle == ""{
			self.ajaxMsg("标题不能为空！", MSG_ERR);
			return;
		}
		uGetGold,err := self.GetInt64("uGetGold");
		if err != nil{
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		if uGetGold < 0 || uGetGold >= 1000000{
			self.ajaxMsg("补偿金币必须是0-1000000之间", MSG_ERR);
			return
		}
		uCtrNickName := self.GetString("uCtrNickName");

		mailContent := self.GetString("mailContent");
		strDate := libs.GetDateNowString();
		ras := models.UserMailInfo{
			UserID:uUserID,
			GameID:CtrlUserID,
			Title:uMailTitle,
			Content:mailContent,
			Gold:uGetGold,
			Status:0,
			Gid:self.userId,
			OpTime:strDate,
		}
		err = ras.UserUserMailInfoInsertValue();
		if err == nil{
			strOKMessage = fmt.Sprintf("给用户改善：【%s(%d)】的标题为【%s】内容为【%s】金币为【%d】的邮件成功！",uCtrNickName,CtrlUserID,uMailTitle,mailContent,uGetGold);
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			self.ajaxMsg(strOKMessage, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);
		
	}else if CtrlType == 1014{
		uCtrlDevstring := self.GetString("uCtrlDevstring");
		if uCtrlDevstring == ""{
			self.ajaxMsg("设备码为空，暂不支持,有需要请联系！", MSG_ERR);
			return;
		}
		ras := models.UserCtrlInfo{
			//USERID:CtrlUserID,
			NTYPE:14,
			DEVSTRING:uCtrlDevstring,
			CHEATREASON:uCtrlReaSonStr,
		}
		err = ras.UserCtrlInfoInsertValue();
		if err == nil{
			strOKMessage = "关联锁定机器码：【"+uCtrlDevstring+"】成功！"
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			self.ajaxMsg(strOKMessage, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);
	}else if CtrlType == 1015{
		uCtrlStatus,err := self.GetInt("uCtrlStatus");
		uCtrlName := self.GetString("uCtrlName");
		if uCtrlStatus != 0 && uCtrlStatus != 1{
			self.ajaxMsg("关怀值不正确！", MSG_ERR);
			return;
		}
		if err != nil {
			self.ajaxMsg(err.Error(), MSG_ERR);
			return;
		}
		ras := models.UserInfo{
			USERID:CtrlUserID,
			Is_follow:uCtrlStatus,
		
		}
		err = ras.ModefyUserInfoFollow();
		if err == nil{
			str := ""
			if uCtrlStatus  == 1{
				str = 	"设置关怀"
			}else if uCtrlStatus == 0{
				str = 	"取消关怀"
			}
			
			strOKMessage = fmt.Sprintf("将【%s(%d)】%s成功！",uCtrlName,CtrlUserID,str);
			self.AddOperationLog(fmt.Sprintf("%s",strOKMessage),1)
			self.ajaxMsg(strOKMessage, MSG_OK);
			return;
		}
		self.ajaxMsg(err.Error(), MSG_ERR);
	}
	self.ajaxMsg("失败", MSG_ERR);
	return;
}
func (self *UsersFinduserController) ModifyUserGold(){
	self.Data["pageTitle"] = "修改用户金币"
	self.Data["uCtrlType"] = 1000
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) ModifyUserCtRate(){
	self.Data["pageTitle"] = "修改用户作弊率"
	self.Data["uCtrlType"] = 1001
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) ModifyUserStatus(){
	self.Data["pageTitle"] = "锁定用户"
	self.Data["uCtrlType"] = 1002
	self.Data["uCtrlStaus"] = 1
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) ModifyUserStatus0(){
	self.Data["pageTitle"] = "解锁用户"
	self.Data["uCtrlType"] = 1002
	self.Data["uCtrlStaus"] = 0
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) ModifyUserKind(){
	self.Data["pageTitle"] = "修改用户类型"
	self.Data["uCtrlType"] = 1003
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) ModifyUserDiamonds(){
	self.Data["pageTitle"] = "修改用户钻石"
	self.Data["uCtrlType"] = 1006
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) ModifyUserTickets(){
	self.Data["pageTitle"] = "修改用户礼券"
	self.Data["uCtrlType"] = 1007
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}

func (self *UsersFinduserController) ModifyUserGameID(){
	self.Data["pageTitle"] = "修改用户推广号"
	self.Data["uCtrlType"] = 1008
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) ModifyPass() {
	self.Data["pageTitle"] = "修改用户密码"
	self.Data["uCtrlType"] = 1009
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) ModifyNicknameDes(){
	self.Data["pageTitle"] = "修改用户昵称-签名"
	self.Data["uCtrlType"] = 1010
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) ModifyUserMoble(){
	self.Data["pageTitle"] = "解绑手机"
	self.Data["uCtrlType"] = 1011
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) SendMailToUser(){
	self.Data["pageTitle"] = "给用户发邮件"
	self.Data["uCtrlType"] = 1013
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)
	self.display()
}
func (self *UsersFinduserController) LockUsersbyMac() {
	self.Data["pageTitle"] = "关联点控"
	self.Data["uCtrlType"] = 1014
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}
func (self *UsersFinduserController) ModifyUsersSetgh() {
	self.Data["pageTitle"] = "设置关怀"
	self.Data["uCtrlType"] = 1015
	self.Data["uCtrlStaus"] = 1
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}
func (self *UsersFinduserController) ModifyUsersSetnogh() {
	self.Data["pageTitle"] = "取消关怀"
	self.Data["uCtrlType"] = 1015
	self.Data["uCtrlStaus"] = 0
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}


func (self *UsersFinduserController) RecordLogin() {
	self.Data["pageTitle"] = "登录记录"

	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}
func (self *UsersFinduserController) RecordLoginTable() {
	
	//列表
	page, err := self.GetInt("page")
	if err != nil {
		page = 1
	}
	limit, err := self.GetInt("limit")
	if err != nil {
		limit = 30
	}

	self.pageSize = limit

	//用户信息
	UserGameID := self.GetString("UserGameID");
   
    BeforDateTime := self.GetString("BeforDateTime");
    AfterDateTime := self.GetString("AfterDateTime");
  


    //推广号
    strsql := "";
	strsql = fmt.Sprintf("%s AND GameID = %s",strsql,UserGameID);

	if  BeforDateTime != "" {
		
		strsql = fmt.Sprintf("%s AND EnterTime >= UNIX_TIMESTAMP('%s')",strsql,BeforDateTime);
	}
	
	if  AfterDateTime != "" {
		
		strsql = fmt.Sprintf("%s AND EnterTime <= UNIX_TIMESTAMP('%s')",strsql,AfterDateTime);
	}
	

	result, count,_ := models.RecordLoginData(page,self.pageSize,strsql)
	list := make([]map[string]interface{}, len(result))
	for k, v := range result {
		row := make(map[string]interface{})

		row["UserID"] = v["GameID"]
		row["UserNickName"] = v["NickName"]

		row["roomID"] = v["SID"];

		row["roomName"] = v["RoonName"]
		row["ugold"] = v["Gold"]
		row["uinsergold"] = v["InsureGold"]
		row["uallgold"] = v["ZiChan"]
		row["loginTime"] = v["ET"]
		row["loginip"] = v["IP"]
		row["loginmac"] = v["MAC"]
		row["loginkind"] = models.GetUserLoginKindName(v["Tpye"])
		list[k] = row
	}

	self.ajaxList("成功", MSG_OK, count, list)	
}

func (self *UsersFinduserController) RecordGoldChange() {
	self.Data["pageTitle"] = "金币变动记录"

	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}

func (self *UsersFinduserController) RecordGoldChangeTable() {


	//用户信息
	UserGameID  := self.GetString("UserGameID");
	
    	
    //列表
    page, err := self.GetInt("page")
	if err != nil {
		page = 1
	}
	limit, err := self.GetInt("limit")
	if err != nil {
		limit = 30
	}
	self.pageSize = limit

    BeforDateTime := self.GetString("BeforDateTime");
	AfterDateTime := self.GetString("AfterDateTime");
	uRoomID := self.GetString("uRoomID");
	uMemo := self.GetString("uMemo");

	//推广号
	strsql := "";
	strsql = fmt.Sprintf("%s AND GameID = %s",strsql,UserGameID);

	if  BeforDateTime != "" {
			
		strsql = fmt.Sprintf("%s AND ChangeTime >= UNIX_TIMESTAMP('%s')",strsql,BeforDateTime);
	}
		
	if  AfterDateTime != "" {		
		strsql = fmt.Sprintf("%s AND ChangeTime <= UNIX_TIMESTAMP('%s')",strsql,AfterDateTime);
	}
	if uRoomID != ""{
		strsql = fmt.Sprintf("%s AND ServerID = %s",strsql,uRoomID);
	}

	if uMemo != ""{
		strsql = fmt.Sprintf("%s AND Memo LIKE '%%%s%%'",strsql,uMemo);
	}
		
	//filters := make([]interface{}, 0)
	//filters = append(filters, "UserScoreChange_20171106")
	//filters = append(filters, "UserScoreChange_20171107")

	filters := models.GetUserGoldChangeTableNames(BeforDateTime,AfterDateTime,"Y-m-d H:i:s");
	//fmt.Println("wwwwwwwwwwwwwww",filters);
	result, count,_ := models.RecordGoldChangeData(page,self.pageSize,strsql,filters...);
	list := make([]map[string]interface{}, len(result))
	for k, v := range result {
		row := make(map[string]interface{})

		row["logTime"] = v["ChangeTime"]
		row["logs"] = v["Memo"]

		row["goldChange"] = v["ChangeGold"];

		row["goldChange1"] = v["CGold"]
		row["golds"] = v["Gold"]
		row["golds1"] = v["InsureGold"]
		row["allGolds"] = v["ZiChan"]
		row["ctrlstatus"] = v["CheatRate"]
		list[k] = row
	}

	
	strsql2 := fmt.Sprintf(" AND UI.GameID = %s",UserGameID);

	TitleData,_ := models.UserInfoDataByCondtion(strsql2);

	self.ajaxTilteList("成功", MSG_OK, count,TitleData,list)	

}

func (self *UsersFinduserController) RecordCharge() {
	self.Data["pageTitle"] = "充值记录"

	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}
func (self *UsersFinduserController) RecordChargeTable() {


	//用户信息
	UserGameID  := self.GetString("UserGameID");
	UserCkind := self.GetString("UserCkind");
	if UserCkind == ""{
		return;
	}
   	if UserCkind == "1" {
	    	//列表
		page, err := self.GetInt("page")
		if err != nil {
			page = 1
		}
		limit, err := self.GetInt("limit")
		if err != nil {
			limit = 30
		}

		self.pageSize = limit

    	BeforDateTime := self.GetString("BeforDateTime");
	    AfterDateTime := self.GetString("AfterDateTime");
	  	userpathform := self.GetString("userpathform");
	  	userlvsign := self.GetString("userlvsign");

	    //推广号
	    strsql := "";
	    if UserGameID != ""{
	    	strsql = fmt.Sprintf("%s AND GAMEID = %s",strsql,UserGameID);
	    }
		
		if  BeforDateTime != "" {
			
			strsql = fmt.Sprintf("%s AND PURCHASETIME >= UNIX_TIMESTAMP('%s')",strsql,BeforDateTime);
		}
		
		if  AfterDateTime != "" {
			
			strsql = fmt.Sprintf("%s AND PURCHASETIME <= UNIX_TIMESTAMP('%s')",strsql,AfterDateTime);
		}
		if userpathform != ""{
			strsql = fmt.Sprintf("%s AND PLATFORM = %s",strsql,userpathform);
		}

		if userlvsign != ""{
			strsql = fmt.Sprintf("%s AND LVSIGN = %s",strsql,userlvsign);
		}
		

		result, count,_ := models.RecordChargeData(page,self.pageSize,strsql);
		list := make([]map[string]interface{}, len(result))
		for k, v := range result {
			row := make(map[string]interface{})

			row["ugameID"] = v["GAMEID"]
			row["unickname"] = v["NICKNAME"]

			row["urmb"] = v["RMB"];

			row["getGold"] = v["SCORE"]
		
			row["upurtime"] = v["PURCHASETIME"]
			row["pathform"] = models.GetUserDeviceName(v["PLATFORM"]);
		
			list[k] = row
		}


		self.ajaxList("成功", MSG_OK, count, list)	
	} else if UserCkind == "2" {
	
		
		ret,_,_ := models.RecordChargeDataTitle();

		list := make(map[string]interface{})
		if len(ret) >= 1{
			list["DATA1"] = ret[0]["RMB"]
			list["DATA2"] = ret[0]["ALLPRUCOUNT"]

		}
  		
		self.ajaxList("成功", MSG_OK, 0, list)	
	}
}

func (self *UsersFinduserController) RecordGift() {
	self.Data["pageTitle"] = "礼物赠送记录"

	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}
func (self *UsersFinduserController) RecordGiftTable() {

}


func (self *UsersFinduserController) RecordShiwu() {
	self.Data["pageTitle"] = "实物兑换记录"

	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}
func (self *UsersFinduserController) RecordShiwuTable() {

}

func (self *UsersFinduserController) RecordLock() {
	self.Data["pageTitle"] = "锁定记录"

	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}
func (self *UsersFinduserController) RecordLockTable() {

		//用户信息
		UserGameID  := self.GetString("UserGameID");
   
	    //列表
		page, err := self.GetInt("page")
		if err != nil {
			page = 1
		}
		limit, err := self.GetInt("limit")
		if err != nil {
			limit = 30
		}

		self.pageSize = limit

    	BeforDateTime := self.GetString("BeforDateTime");
	    AfterDateTime := self.GetString("AfterDateTime");
	  

	    //推广号
	    strsql := "";
	    if UserGameID != ""{
	    	strsql = fmt.Sprintf("%s AND GAMEID = %s",strsql,UserGameID);
	    }
		
		if  BeforDateTime != "" {
			
			strsql = fmt.Sprintf("%s AND OPRATETIME >= UNIX_TIMESTAMP('%s')",strsql,BeforDateTime);
		}
		
		if  AfterDateTime != "" {
			
			strsql = fmt.Sprintf("%s AND OPRATETIME <= UNIX_TIMESTAMP('%s')",strsql,AfterDateTime);
		}
		
		result, count,_ := models.RecordLockData(page,self.pageSize,strsql);
		list := make([]map[string]interface{}, len(result))
		for k, v := range result {
			row := make(map[string]interface{})

			row["UserID"] = v["GAMEID"]
			row["UserNickName"] = v["NICKNAME"]

			row["RegTime"] = v["REGTIME"];

			row["LastLoginTime"] = v["LASTLIGNTIME"]
		
			row["uallgold"] = v["ALLGOLD"]
			row["uallwin"] = v["ALLWIN"]
			row["oType"] = models.GetLockStatus(v["TYPE"]);
			row["reson"] = v["CONTEXT"]
			row["operatetime"] = v["OPRATETIME"]
			row["GmName"] = v["RealName"]

			list[k] = row
		}


		self.ajaxList("成功", MSG_OK, count, list)	
}

func (self *UsersFinduserController) RecordMail() {
	self.Data["pageTitle"] = "邮件列表"

	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}
func (self *UsersFinduserController) RecordMailTable() {
	//用户信息
	UserGameID  := self.GetString("UserGameID");


	BeforDateTime := self.GetString("BeforDateTime");
	AfterDateTime := self.GetString("AfterDateTime");
	GMUserName := self.GetString("GMUserName");
	isabnormal := self.GetString("isabnormal");
	userWinLose := self.GetString("userWinLose");

	//推广号
	strsql := "";
	if UserGameID != "" && isabnormal == "1" {
	   	strsql = fmt.Sprintf("%s  AND M.GameID = %s",strsql,UserGameID);
	}
	if UserGameID != "" && isabnormal == "2" {
	   	strsql = fmt.Sprintf("%s  AND M.UserID = %s",strsql,UserGameID);
	}
	if UserGameID != "" && isabnormal == "3" {
	   	strsql = fmt.Sprintf("%s  AND U.NickName = '%s'",strsql,UserGameID);
	}
			
	if  BeforDateTime != "" {	
		strsql = fmt.Sprintf("%s AND OpTime >= '%s'",strsql,BeforDateTime);
	}
		
	if  AfterDateTime != "" {
		strsql = fmt.Sprintf("%s AND OpTime <= '%s'",strsql,AfterDateTime);
	}

	if GMUserName != ""{
		strsql = fmt.Sprintf("%s AND RealName LIKE '%%%s%%'",strsql,GMUserName);
	}

	if userWinLose != ""{
		strsql = fmt.Sprintf("%s   AND M.`Status`= %s ",strsql,userWinLose);
	}

  
	    	//列表
		page, err := self.GetInt("page")
		if err != nil {
			page = 1
		}
		limit, err := self.GetInt("limit")
		if err != nil {
			limit = 30
		}

		self.pageSize = limit



		result, count,_ := models.RecordMailData(page,self.pageSize,strsql);
		list := make([]map[string]interface{}, len(result))
		for k, v := range result {
			row := make(map[string]interface{})

			row["ugameID"] = v["MGAMEID"]
			row["unickname"] = v["USERNAME"]
			row["GMUserName"] = v["RealName"];
			row["OprateTime"] = v["OpTime"]
			row["GetGold"] = v["MGOLD"]
			row["title"] = v["Title"];
			row["Content"] = v["Content"];
			row["Status"] = models.GetMailStatus(v["MStatus"]);
		
			list[k] = row
		}

		TitleData,_ := models.RecordMailDataTitle(strsql);
		self.ajaxTilteList("成功", MSG_OK, count,TitleData,list)
}

func (self *UsersFinduserController) RecordCtrl() {
	self.Data["pageTitle"] = "点控制记录"
	self.AddOperationLog(fmt.Sprintf("进入【%s】页面",self.Data["pageTitle"]),1)

	self.display()
}

func (self *UsersFinduserController) RecordCtrlTable() {


	//用户信息
	UserGameID  := self.GetString("UserGameID");
	UserCkind := self.GetString("UserCkind");
	if UserCkind == ""{
		return;
	}

	BeforDateTime := self.GetString("BeforDateTime");
	AfterDateTime := self.GetString("AfterDateTime");
	GMUserName := self.GetString("GMUserName");
	//isabnormal := self.GetString("isabnormal");
	userWinLose := self.GetString("userWinLose");

	//推广号
	strsql := "";
	if UserGameID != ""{
	   	strsql = fmt.Sprintf("%s AND GAMEID = %s",strsql,UserGameID);
	}
		
	if  BeforDateTime != "" {	
		strsql = fmt.Sprintf("%s AND Writedate >= UNIX_TIMESTAMP('%s')",strsql,BeforDateTime);
	}
		
	if  AfterDateTime != "" {
		strsql = fmt.Sprintf("%s AND Writedate <= UNIX_TIMESTAMP('%s')",strsql,AfterDateTime);
	}

	if GMUserName != ""{
		strsql = fmt.Sprintf("%s AND RealName LIKE '%%%s%%'",strsql,GMUserName);
	}

	if userWinLose == "0"{
		strsql = fmt.Sprintf("%s AND NewlCheatRate > 0 ",strsql);
	}
	if userWinLose == "1"{
		strsql = fmt.Sprintf("%s AND NewlCheatRate < 0 ",strsql);
	}

   	if UserCkind == "1" {
	    	//列表
		page, err := self.GetInt("page")
		if err != nil {
			page = 1
		}
		limit, err := self.GetInt("limit")
		if err != nil {
			limit = 30
		}

		self.pageSize = limit



		result, count,_ := models.RecordCtrlData(page,self.pageSize,strsql);
		list := make([]map[string]interface{}, len(result))
		for k, v := range result {
			row := make(map[string]interface{})

			row["ugameID"] = v["GAMEID"]
			row["unickname"] = v["NICKNAME"]
			row["GMUserName"] = v["RealName"];
			row["ctrlTime"] = v["Writedate"]
			row["Userwinlose"] = v["LtotalScore"]
			row["oldrate"] = v["OldlCheatRate"];
			row["newrate"] = v["NewlCheatRate"];
			row["ctrlscore"] = v["NewlCheatLimit"]
			str := fmt.Sprintf("作弊率由%s变为%s,作弊限额由%s变为%s",v["OldlCheatRate"].(string),v["NewlCheatRate"].(string),v["OldlCheatLimit"].(string),v["NewlCheatLimit"].(string))
			row["changlogs"] = str;
			row["reason"] = v["Reson"]
			list[k] = row
		}


		self.ajaxList("成功", MSG_OK, count, list)	
	} else if UserCkind == "2" {
	
		
		ret,_:= models.RecordCtrlDataTitle(strsql);

		list := make(map[string]interface{})
		if len(ret) >= 2{
			list["DATA1"] = ret[0];
			list["DATA2"] = ret[1];

		}
  		
		self.ajaxList("成功", MSG_OK, 0, list)	
	}
}





